#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main()
{
    int t = 0;
    scanf("%d", &t);
    while (t--)
    {
        int x, n;
        scanf("%d %d", &x, &n);
        if (n == 1)
            printf("%d\n", x);
        else if (n == 2)
            printf("%d\n", 1);
        else
        {
            int maxgold = 0;
            for (int numgold = x; numgold >= 0; numgold--)
            {
                int count = 1;
                int t1 = n - 1;
                int t2 = x - numgold;
                for (int j = 2; j <= n; j++)
                {
                    if (t2 == 0)
                    {
                        break;
                    }
                    if ((double)numgold > (double)t2 / t1)
                    {
                        count++;
                    }
                    t1--;
                }

                if (count >= (n - 1) / 2)
                {
                    maxgold = numgold;
                    break;
                }
            }
            printf("%d\n", maxgold);
        }

    }
    return 0;
}

